package com.dream.libxrec.rec.audio;

import android.content.Context;

import com.dream.libmp3lame.MP3Lame;
import com.dream.libxrec.utils.ArrayUtils;

public class MP3Recorder {
    private final MP3Lame mLame = new MP3Lame();
    private final String mp3Path;
    public MP3Recorder(Context ct,
                       String mp3Path,
                       int sample,
                       int channel,
                       int bitRate,
                       int quality, boolean isVbr){

        this.mp3Path = mp3Path;
        mLame.initRec(mp3Path,sample,sample,channel,channel,
                bitRate,quality,
                isVbr);
    }

    public void write(byte[] pcm,int size){
        if (size <= 0){
            return;
        }

        short[] shorts = new short[pcm.length/2];
        ArrayUtils.toShortLittle(pcm,shorts,size,true);

        mLame.writeRec(shorts,size/2);
    }

    public void release(){
        mLame.flushRec();
        mLame.release();
    }


}
